var http = require('http');
var fs = require('fs');
var url = require('url');
var path = require('path');

var hostname = '127.0.0.1';
var port = 3000;

var server = http.createServer(function (req, res) {
    if (req.url == '/favicon.ico') return;


    fs.readFile('./static/', function (err, data) {
        if (err) {

            fs.readFile('./404.jpg', function(err, data) {
                
                res.end(data);
            });
            return;
            // 如果文件不存在,返回404页面
            fs.readFile('./404.html', function(err, data) {
                res.writeHead(200, {"content-type":"text/html"});
                res.end(data);
            });
            return; 
        }
    

    });
});

server.listen(port, hostname);